slk = require 'slk'

local function createPassiveUbertip(v)
    local d = {}
    if (v.PASSIVE ~= nil) then
        table.insert(d, hColor.seaLight("被动：" .. v.PASSIVE))
    end
    if (v.ATTR ~= nil) then
        table.sort(v.ATTR)
        table.insert(d, hColor.green(slkHelper.attrDesc(v.ATTR, "|n")))
    end
    if (v.Desc ~= nil and v.Desc ~= "") then
        table.insert(d, hColor.grey(v.Desc))
    end
    return string.implode("|n", d)
end

local function createActiveUbertip(v)
    return v.desc
end

local function createPassive(v)
    local obj = slk.ability.Aamk:new(v.Name)
    obj.Name = v.Name
    obj.hero = 0
    obj.levels = v.levels or 1
    if obj.levels == 1 then
        obj.Tip = v.Name
        obj.Ubertip = createPassiveUbertip(v)
        obj.DataA1 = 0
        obj.DataB1 = 0
        obj.DataC1 = 0
    else
        for i = 1, v.levels do
            obj['Tip' .. i] = v.Name
            obj['Ubertip' .. i] = createPassiveUbertip(v)
            obj['DataA' .. i] = 0
            obj['DataB' .. i] = 0
            obj['DataC' .. i] = 0
        end
    end
    obj.race = v.race or "other"
    obj.Art = v.Art or "ReplaceableTextures\\PassiveButtons\\PASBTNStatUp.blp"
    obj.ButtonPos1 = v.ButtonPos1 or 0
    obj.ButtonPos2 = v.ButtonPos2 or 0
end

-- 以通魔为模板生成主动技能
local function createActive(v)
    local obj = slk.ability.ANcl:new(v.Name)
    obj.Name = v.Name
    obj.Hotkey = v.Hotkey or 'C' --快捷键
    obj.Art = v.Art or "ReplaceableTextures\\CommandButtons\\BTNDeathPact.blp"
    obj.hero = 0
    obj.levels = v.levels or 1
    obj.ButtonPos1 = v.ButtonPos1 or 0
    obj.ButtonPos2 = v.ButtonPos2 or 0
    obj.race = v.race or "other"
    obj.Order = v.order
    obj.CasterArt = ''
    obj.EffectArt = ''
    obj.TargetArt = ''
    if obj.levels == 1 then
        obj.Tip = v.Name + '(第1重)'
        obj.Ubertip = createActiveUbertip(v)
        obj.DataA1 = 0  -- 施法持续时间
        obj.DataB1 = v.targetType -- 0无目标 1单位目标 2点目标 3单位目标或点目标
        obj.DataC1 = v.extra -- 可多选，2进制 1图标可见 2目标选取图像 4物理魔法 8通用魔法 16单独施放
        obj.DataD1 = v.actionTime or 0.98 -- 动作持续时间
        obj.DataE1 = 0  -- 使其他技能无效
        obj.DataF1 = v.order or 'channel'  -- 基础命令ID 重复会导致技能冲突，必须是现有的ID，自定义无效
        obj.Cool1 = v.cool(1) or 0
        obj.Cost1 = v.cost(1) or 0
        obj.Rng1 = v.range(1) or 500
    else
        for i = 1, v.levels do
            obj['Tip' .. i] = v.Name + '(第' .. i .. '重)'
            obj['Ubertip' .. i] = createActiveUbertip(v)
            obj['DataA' .. i] = 0  -- 施法持续时间
            obj['DataB' .. i] = v.targetType -- 0无目标 1单位目标 2点目标 3单位目标或点目标
            obj['DataC' .. i] = v.extra -- 可多选，2进制 1图标可见 2目标选取图像 4物理魔法 8通用魔法 16单独施放
            obj['DataD' .. i] = v.actionTime or 0.98 -- 动作持续时间
            obj['DataE' .. i] = 0  -- 使其他技能无效
            obj['DataF' .. i] = v.order or 'channel'  -- 基础命令ID 重复会导致技能冲突，必须是现有的ID，自定义无效
            obj['Cool' .. i] = v.cool(i) or 0
            obj['Cost' .. i] = v.cost(i) or 0
            obj['Rng' .. i] = v.range(i) or 500
        end
    end
end

-- 被动技能
local passiveSkills = {
    {
        Name = "太祖长拳",
        ButtonPos1 = 0,
        ButtonPos2 = 1,
        levels = 9,
        PASSIVE = "对周围敌方单位造成伤害",
        Desc = "丐帮独门武学"
    },

}

for _, v in pairs(passiveSkills) do
    createPassive(v)
end
